package wec_wallet.ebo.com.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.ArrayList;

import wec_wallet.ebo.com.R;
import wec_wallet.ebo.com.bean.Address;

/**
 * Created by user on 2017-09-09.
 */

public class AccountAdapter extends RecyclerView.Adapter<AccountAdapter.MyViewHolder> {
    private ArrayList<Address> list = new ArrayList<>();
    private Context context;
    private OnItemClickLitener mOnItemClickLitener;
    public AccountAdapter(ArrayList<Address> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_manager_address, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.name.setText(list.get(position).getName());
        holder.content.setText(list.get(position).getAddress());
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView name;
        private TextView content;
        private ImageView image;

        public MyViewHolder(View itemView) {
            super(itemView);
            name =(TextView) itemView.findViewById(R.id.item_name);
            content =(TextView) itemView.findViewById(R.id.item_content);
            image =(ImageView) itemView.findViewById(R.id.item_img);
        }
    }


}
